<?php


namespace App\Http\Controllers\user;


use App\Engine\BaseController;
use App\Models\Banner as BannerModel;
use App\Models\HouseType;
use function app\Utils\go;
use App\Models\House as HouseModel;
use App\Models\Sys as SysModel;

class Common extends BaseController
{
    /**
     * 获取配置文件
     */
    public function sys()
    {
        $res=SysModel::get_sys_obj();
        return go($res);
    }

    /**获取广告图
     * @return array
     */
    public function banner()
    {
        $api_url=SysModel::getValue('api_url');
        $res=BannerModel::with('img')->orderBy('sort','asc')->get()->map(function ($item) use ($api_url){
            $item['title']=$item['name'];
            $item['image']=$api_url.$item['img']['url'];
            return $item;
        });
        return go($res);
    }


    /**获取house
     * @return array
     */
    public function house()
    {
        $res=HouseModel::orderBy('id','desc')->get();
        return go($res);
    }

    public function house_type()
    {
        $res=HouseType::with('house')->get();
        return go($res);
    }

    public function house_id()
    {
        $res=HouseModel::with(['types','projects','collection'])->where('id',$this->get['id'])->first();
        return go($res);
    }
    


}
